<?php
/**
 * @author Matteo Vigoni <mattevigo@gmail.com>
 * @package core.site	
 * @version 2.0
 * 
 * The Blogset contains an array of Blogpost filtered from month, tag and category
 */
require_once($_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR."config_dbentity.php");

import('core.Object');
import('core.DB');
import('core.DBEntity');
import('core.blog.Blogpost');

class Blogset extends Object
{	
	var $db;
	var $set = NULL;
	
	public function __construct( DB $db )
	{
		$this->db = $db;
	}
	
	/**
	 * 
	 */
	public function getSet()
	{
		return $this->set;
	}
	
	/**
	 * Retrive all blogpost ordered by date (DESC)
	 * 
	 * @param $from
	 * @param $limit
	 */
	public function setAll( $from=0, $limit=NULL )
	{
		$this->set = Blogpost::getArray( $this->db, 'seed_id DESC', 1, $limit, $from );
	}
	
	/**
	 * 
	 * @param string $month
	 */
	public function setMonth( $month=NULL, $from=0, $limit=NULL )
	{
		$time = 0;
		if( $month == NULL )
		{
			$time = strtotime( date('F Y', time()) );
		}
		else
		{
			$time =  strtotime( $month );
		}
		
		$filter = "seed_date >= $time";
		
		$this->set = Blogpost::getArray( $this->db, 'seed_id DESC', $filter, $from, $limit );
	}
}